package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.model.LiveModel;
import com.bilibili.bilibili.utils.FullGridView;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者：郭传沛 on 2017/3/10 19:24
 * 邮箱：bestyourselfgcp@163.com
 * 类用途:
 */

public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<LiveModel.DataBean.PartitionsBean> mDataBeen;
    private Context mContext;

    public MyRecyclerAdapter(List<LiveModel.DataBean.PartitionsBean> dataBeen, Context context) {
        mDataBeen = dataBeen;
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.live_recycleritem, parent, false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        myViewHolder.mLive_partition_title.setText(mDataBeen.get(position).getPartition().getName());
        Glide.with(mContext).load(mDataBeen.get(position).getPartition().getSub_icon().getSrc()).into(myViewHolder.mLive_partition_icon);
        myViewHolder.mLive_partition_count.setText("当前" + mDataBeen.get(position).getPartition().getCount() + "个直播");
        MyGridViewAdpter myGridViewAdpter = new MyGridViewAdpter(mContext, mDataBeen.get(position).getLives());
        myViewHolder.mLive_fullgridview.setAdapter(myGridViewAdpter);
    }

    @Override
    public int getItemCount() {
        return mDataBeen.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private final FullGridView mLive_fullgridview;
        private final ImageView mLive_partition_icon;
        private final TextView mLive_partition_title;
        private final TextView mLive_partition_count;

        public MyViewHolder(View itemView) {
            super(itemView);
            mLive_fullgridview = (FullGridView) itemView.findViewById(R.id.live_fullgridview);
            mLive_partition_icon = (ImageView) itemView.findViewById(R.id.live_partition_icon);
            mLive_partition_title = (TextView) itemView.findViewById(R.id.live_partition_title);
            mLive_partition_count = (TextView) itemView.findViewById(R.id.live_partition_count);
        }
    }
}
